#!/bin/bash

SERVER=`pwd | awk -F/ '{print $4}'`

if [ "${SERVER}" == "" ]
then
        echo "path error!"
        exit 1
fi

PID=`ps aux | grep engine | grep -v grep | grep ${SERVER} | awk '{print $2}'`


if [ "${PID}" != "" ]
then
        echo "Stopping ${SERVER} engine..."
        kill ${PID}
	sleep 2
		
	ENGINE_PID=`ps aux | grep engine | grep -v grep | grep ${SERVER} | awk '{print $2}'`
	if [ "${ENGINE_PID}" == "" ]
	then
		echo "kill ${SERVER} engine ok!"
	fi
		
else
	echo "No ${SERVER} engine process found, exits."
	exit 0 
fi
